// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Graph;

public sealed partial class ExploreControls
{
	/// <summary>
	/// <para>To avoid the top-matching documents sample being dominated by a single source of results, it is sometimes necessary to request diversity in the sample.<br/>You can do this by selecting a single-value field and setting a maximum number of documents per value for that field.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("sample_diversity")]
	public Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversity? SampleDiversity { get; set; }

	/// <summary>
	/// <para>Each hop considers a sample of the best-matching documents on each shard.<br/>Using samples improves the speed of execution and keeps exploration focused on meaningfully-connected terms.<br/>Very small values (less than 50) might not provide sufficient weight-of-evidence to identify significant connections between terms.<br/>Very large sample sizes can dilute the quality of the results and increase execution times.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("sample_size")]
	public int? SampleSize { get; set; }

	/// <summary>
	/// <para>The length of time in milliseconds after which exploration will be halted and the results gathered so far are returned.<br/>This timeout is honored on a best-effort basis.<br/>Execution might overrun this timeout if, for example, a long pause is encountered while FieldData is loaded for a field.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("timeout")]
	public Elastic.Clients.Elasticsearch.Serverless.Duration? Timeout { get; set; }

	/// <summary>
	/// <para>Filters associated terms so only those that are significantly associated with your query are included.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("use_significance")]
	public bool UseSignificance { get; set; }
}

public sealed partial class ExploreControlsDescriptor<TDocument> : SerializableDescriptor<ExploreControlsDescriptor<TDocument>>
{
	internal ExploreControlsDescriptor(Action<ExploreControlsDescriptor<TDocument>> configure) => configure.Invoke(this);

	public ExploreControlsDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversity? SampleDiversityValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor<TDocument> SampleDiversityDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor<TDocument>> SampleDiversityDescriptorAction { get; set; }
	private int? SampleSizeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Duration? TimeoutValue { get; set; }
	private bool UseSignificanceValue { get; set; }

	/// <summary>
	/// <para>To avoid the top-matching documents sample being dominated by a single source of results, it is sometimes necessary to request diversity in the sample.<br/>You can do this by selecting a single-value field and setting a maximum number of documents per value for that field.</para>
	/// </summary>
	public ExploreControlsDescriptor<TDocument> SampleDiversity(Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversity? sampleDiversity)
	{
		SampleDiversityDescriptor = null;
		SampleDiversityDescriptorAction = null;
		SampleDiversityValue = sampleDiversity;
		return Self;
	}

	public ExploreControlsDescriptor<TDocument> SampleDiversity(Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor<TDocument> descriptor)
	{
		SampleDiversityValue = null;
		SampleDiversityDescriptorAction = null;
		SampleDiversityDescriptor = descriptor;
		return Self;
	}

	public ExploreControlsDescriptor<TDocument> SampleDiversity(Action<Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor<TDocument>> configure)
	{
		SampleDiversityValue = null;
		SampleDiversityDescriptor = null;
		SampleDiversityDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Each hop considers a sample of the best-matching documents on each shard.<br/>Using samples improves the speed of execution and keeps exploration focused on meaningfully-connected terms.<br/>Very small values (less than 50) might not provide sufficient weight-of-evidence to identify significant connections between terms.<br/>Very large sample sizes can dilute the quality of the results and increase execution times.</para>
	/// </summary>
	public ExploreControlsDescriptor<TDocument> SampleSize(int? sampleSize)
	{
		SampleSizeValue = sampleSize;
		return Self;
	}

	/// <summary>
	/// <para>The length of time in milliseconds after which exploration will be halted and the results gathered so far are returned.<br/>This timeout is honored on a best-effort basis.<br/>Execution might overrun this timeout if, for example, a long pause is encountered while FieldData is loaded for a field.</para>
	/// </summary>
	public ExploreControlsDescriptor<TDocument> Timeout(Elastic.Clients.Elasticsearch.Serverless.Duration? timeout)
	{
		TimeoutValue = timeout;
		return Self;
	}

	/// <summary>
	/// <para>Filters associated terms so only those that are significantly associated with your query are included.</para>
	/// </summary>
	public ExploreControlsDescriptor<TDocument> UseSignificance(bool useSignificance = true)
	{
		UseSignificanceValue = useSignificance;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (SampleDiversityDescriptor is not null)
		{
			writer.WritePropertyName("sample_diversity");
			JsonSerializer.Serialize(writer, SampleDiversityDescriptor, options);
		}
		else if (SampleDiversityDescriptorAction is not null)
		{
			writer.WritePropertyName("sample_diversity");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor<TDocument>(SampleDiversityDescriptorAction), options);
		}
		else if (SampleDiversityValue is not null)
		{
			writer.WritePropertyName("sample_diversity");
			JsonSerializer.Serialize(writer, SampleDiversityValue, options);
		}

		if (SampleSizeValue.HasValue)
		{
			writer.WritePropertyName("sample_size");
			writer.WriteNumberValue(SampleSizeValue.Value);
		}

		if (TimeoutValue is not null)
		{
			writer.WritePropertyName("timeout");
			JsonSerializer.Serialize(writer, TimeoutValue, options);
		}

		writer.WritePropertyName("use_significance");
		writer.WriteBooleanValue(UseSignificanceValue);
		writer.WriteEndObject();
	}
}

public sealed partial class ExploreControlsDescriptor : SerializableDescriptor<ExploreControlsDescriptor>
{
	internal ExploreControlsDescriptor(Action<ExploreControlsDescriptor> configure) => configure.Invoke(this);

	public ExploreControlsDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversity? SampleDiversityValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor SampleDiversityDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor> SampleDiversityDescriptorAction { get; set; }
	private int? SampleSizeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Duration? TimeoutValue { get; set; }
	private bool UseSignificanceValue { get; set; }

	/// <summary>
	/// <para>To avoid the top-matching documents sample being dominated by a single source of results, it is sometimes necessary to request diversity in the sample.<br/>You can do this by selecting a single-value field and setting a maximum number of documents per value for that field.</para>
	/// </summary>
	public ExploreControlsDescriptor SampleDiversity(Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversity? sampleDiversity)
	{
		SampleDiversityDescriptor = null;
		SampleDiversityDescriptorAction = null;
		SampleDiversityValue = sampleDiversity;
		return Self;
	}

	public ExploreControlsDescriptor SampleDiversity(Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor descriptor)
	{
		SampleDiversityValue = null;
		SampleDiversityDescriptorAction = null;
		SampleDiversityDescriptor = descriptor;
		return Self;
	}

	public ExploreControlsDescriptor SampleDiversity(Action<Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor> configure)
	{
		SampleDiversityValue = null;
		SampleDiversityDescriptor = null;
		SampleDiversityDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Each hop considers a sample of the best-matching documents on each shard.<br/>Using samples improves the speed of execution and keeps exploration focused on meaningfully-connected terms.<br/>Very small values (less than 50) might not provide sufficient weight-of-evidence to identify significant connections between terms.<br/>Very large sample sizes can dilute the quality of the results and increase execution times.</para>
	/// </summary>
	public ExploreControlsDescriptor SampleSize(int? sampleSize)
	{
		SampleSizeValue = sampleSize;
		return Self;
	}

	/// <summary>
	/// <para>The length of time in milliseconds after which exploration will be halted and the results gathered so far are returned.<br/>This timeout is honored on a best-effort basis.<br/>Execution might overrun this timeout if, for example, a long pause is encountered while FieldData is loaded for a field.</para>
	/// </summary>
	public ExploreControlsDescriptor Timeout(Elastic.Clients.Elasticsearch.Serverless.Duration? timeout)
	{
		TimeoutValue = timeout;
		return Self;
	}

	/// <summary>
	/// <para>Filters associated terms so only those that are significantly associated with your query are included.</para>
	/// </summary>
	public ExploreControlsDescriptor UseSignificance(bool useSignificance = true)
	{
		UseSignificanceValue = useSignificance;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (SampleDiversityDescriptor is not null)
		{
			writer.WritePropertyName("sample_diversity");
			JsonSerializer.Serialize(writer, SampleDiversityDescriptor, options);
		}
		else if (SampleDiversityDescriptorAction is not null)
		{
			writer.WritePropertyName("sample_diversity");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Graph.SampleDiversityDescriptor(SampleDiversityDescriptorAction), options);
		}
		else if (SampleDiversityValue is not null)
		{
			writer.WritePropertyName("sample_diversity");
			JsonSerializer.Serialize(writer, SampleDiversityValue, options);
		}

		if (SampleSizeValue.HasValue)
		{
			writer.WritePropertyName("sample_size");
			writer.WriteNumberValue(SampleSizeValue.Value);
		}

		if (TimeoutValue is not null)
		{
			writer.WritePropertyName("timeout");
			JsonSerializer.Serialize(writer, TimeoutValue, options);
		}

		writer.WritePropertyName("use_significance");
		writer.WriteBooleanValue(UseSignificanceValue);
		writer.WriteEndObject();
	}
}